package com.theyeasy.dvmini.pc.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.theyeasy.dvmini.model.Postertemplet;
import com.theyeasy.dvmini.pc.controller.BaseController;
import com.theyeasy.dvmini.service.PosterService;
import com.theyeasy.dvmini.vo.Vo_msg;
 

@Controller
@RequestMapping("/poster")
public class PosterController extends BaseController{
	
    @Autowired
    PosterService posterService;
    
    @RequestMapping("/coordinate")
    public ModelAndView templetIndex(){
        ModelAndView mv = new ModelAndView("/pc/poster/coordinate");
        return mv;
    }
    
    @RequestMapping("/poster")
    public ModelAndView poster(){
        ModelAndView mv = new ModelAndView("/pc/poster/poster");
        return mv;
    }
    
    @RequestMapping("/posterlist")
    public ModelAndView posterlist(){
        ModelAndView mv = new ModelAndView("/pc/poster/posterlist");
     
        return mv;
    }
    
    //模板列表
    @RequestMapping(value = "/templetList")
    @ResponseBody
    public Object templetList(Integer page) {
        
        return new Vo_msg(0,posterService.getPosterList(page));
    }
    
    //添加模板
    @RequestMapping(value = "/addtemplet")
    @ResponseBody
    public Object addtemplet(String name,String imgurl,int x,int y,int width,int height,int posttype) {
        String result=posterService.addPoster(name, imgurl, x, y, width, height, posttype);
        if(result.equals("ok")){
             
            return new Vo_msg(0,"添加成功");
        }else{
            return new Vo_msg(-1,result);
        }
    }
    
    //修改模板
    @RequestMapping(value = "/updatetemplet")
    @ResponseBody
    public Object updatetemplet(HttpServletRequest request,Integer id,String name,String imgurl,int x,int y,int width,int height,int posttype) {
        String result=posterService.updatePoster(id, name, imgurl, x, y, width, height, posttype);
        if(result.equals("ok")){
            
            return new Vo_msg(0,"修改成功");
        }else{
            return new Vo_msg(-1,result);
        }
    }
    
    //删除模板
    @RequestMapping(value = "/deletetemplet")
    @ResponseBody
    public Object deletetemplet(Integer id) {
        String result=posterService.deletePoster(id);
        if(result.equals("ok")){
            return new Vo_msg(0,"删除成功");
        }else{
            return new Vo_msg(-1,result);
        }
    }
    
    //获取
    @RequestMapping(value = "/getPoster")
    @ResponseBody
    public Object getPoster(HttpServletRequest request,Integer id) {
   
        Postertemplet templet=posterService.getPoster(id);
        if(templet!=null){
            return new Vo_msg(0,templet);
        }else{
            return new Vo_msg(-1,"获取失败，数据为空");
        }
    }
    
    //海报模板下拉
    @RequestMapping(value = "/getAllPostertemplet")
    @ResponseBody
    public Object getAllPostertemplet() {
        
        return new Vo_msg(0,posterService.getAllPostertemplet());
    }
     
}